﻿<form method="post">
    @Html.AntiForgeryToken()
    <div class="querybar">
        <table cellpadding="0" cellspacing="0" border="0" width="100%">
            <tr>
                <td>
                    名称：<input type="text" class="mytext" id="Name1" name="Name1" value="" style="width:150px" />
                    标题：<input type="text" class="mytext" id="Title1" name="Title1" value="" style="width:150px" />
                    类型：<select id="Type" name="Type" class="myselect">
                            <option value=""></option>
                            <option value="0">顶部统计</option>
                            <option value="1">左边模块</option>
                            <option value="2">右边模块</option>
                        </select>
                    <input type="button" class="mybutton" onclick="query(null, 1);" value="&nbsp;查&nbsp;询&nbsp;" />
                    <input type="button" onclick="edit(); return false;" value="&nbsp;添&nbsp;加&nbsp;" class="mybutton" />
                    <input type="button" class="mybutton" name="deletebut" value="&nbsp;删&nbsp;除&nbsp;" onclick="del();" />
                </td>
            </tr>
        </table>
    </div>
    <table id="listtable"></table>
    <div class="buttondiv"></div>
</form>
<script type="text/javascript">
    var curPageSize;
    var curPageNumber;
    $(function () {
        $("#listtable").jqGrid({
            url: "Query?@Html.Raw(ViewData["query"])",
            postData: { "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() },
            mtype: 'POST',
            datatype: "json",
            colNames: ['模块名称', '显示标题', '类型', '数据来源', '使用对象', '备注', ''],
            colModel: [
                { name: 'Name', index: 'Name' },
                { name: 'Title', index: 'Title' },
                { name: 'Type', index: 'Type', align: "left" },
                { name: 'DataSourceType', index: 'DataSourceType', align: "left" },
                { name: 'UseOrganizes', index: 'UseOrganizes', align: "left" },
                { name: 'Note', index: 'Note', align: "left", width: 110 },
                { name: 'Opation', index: '', sortable: false, align: "left", width: 50 }
            ],
            sortname: "Sort",
            sortorder: "desc",
            height: '100%',
            multiselect: true,
            width: $(window).width(),
            loadComplete: function () {
                var gridObj = $("#listtable");
                var records = gridObj.getGridParam("userData");
                curPageSize = records.pagesize;
                curPageNumber = records.pagenumber;
                $(".buttondiv").html(RoadUI.Core.getPager1(records.total, records.pagesize, records.pagenumber, "query"));
            }
        });

    });
    $(window).resize(function () {
        $("#listtable").setGridWidth($(window).width());
    });
    function query(size, number) {
        var data = {
            __RequestVerificationToken: $("input[name='__RequestVerificationToken']").val(),
            Name1: $("#Name1").val(), Title1: $("#Title1").val(), Type: $("#Type").val(),
            pagesize: size || curPageSize, pagenumber: number || curPageNumber
        };
        $("#listtable").setGridParam({ postData: data }).trigger("reloadGrid");
    }
    function edit(id) {
        window.location = 'Edit?id=' + (id || "") + "&@Html.Raw(ViewData["query"])";
    }
    function del() {
        var rowIds = $("#listtable").jqGrid('getGridParam', 'selarrrow');
        if (rowIds.length === 0) {
            alert("您没有选择要删除的项!");
            return false;
        }
        if (!confirm('真的要删除吗?')) {
            return false;
        }
        $.ajax({
            url: "Delete?@Html.Raw(ViewData["query"])" + "&pagesize=" + curPageSize + "&pagenumber=" + curPageNumber,
            data: { "ids": rowIds.join(","), "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() },
            type: "post",
            success: function (txt) {
                alert(txt);
                query();
            }
        });
        return true;
    }
</script>
